#include "myelf.h"
#include "new_sprintf.h"
const char *test_string_0 = "test_string_0";
const char *location_string = "location_string";
const char *test_string_1 = "test_string_1";


/*
    演示通过定位字符串重定位功能，用在常量字符串在内存地址与在rodata段地址不一致的场景
*/
int main(int argc, char **argv)
{

    if (argc != 2)
    {
        printf("Usage: ./test1 test1 \n");
        return 0;
    }
    rodata_info_t *info_p = load_elf_file(argv[1]);
    if (NULL != info_p)
    {
        if (64 == info_p->class_type)
        {
            char *ptr = location_string_relocatio_offset(info_p, "location_string");
            if (NULL != ptr)
            {
                printf("get string frome rodata:%s\n", ptr + (int64_t)(test_string_0) - (int64_t)(location_string));
                printf("get string frome rodata:%s\n", ptr + (int64_t)(test_string_1) - (int64_t)(location_string));
            }
        }
    }
    else
    {
        printf("error when load_elf_file\n");
    }
    free_elf_resource(info_p);
    return 0;
}